package com.example.sunsg.okhttptest.viewholder;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;

import com.breadtrip.R;
import com.example.sunsg.okhttptest.util.Util;
import com.facebook.drawee.view.SimpleDraweeView;

/**
 * Created by sunsg on 16/3/9.
 *
 * layout R.layout.item_activity_spot_edit_image
 */
public class SpotEditItemImageHolder extends RecyclerView.ViewHolder{
    public SimpleDraweeView mSimpleDraweeView;
    public EditText eTthuzhu;
    public int padding15;
    public SpotEditItemImageHolder(View itemView) {
        super(itemView);
        initView(itemView);
        bindEvent();
    }

    private void initView(View view){
        padding15 = Util.dp2px(view.getContext(),15);
        mSimpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.image);
        eTthuzhu = (EditText) view.findViewById(R.id.et_tuzhu);
    }

    private void bindEvent(){
        eTthuzhu.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    getFocus();
                }else{
                    loseFocus();
                }
            }
        });
    }

    private void getFocus(){
        eTthuzhu.requestFocus();
        eTthuzhu.setFocusable(true);
        eTthuzhu.setMinLines(3);
        eTthuzhu.setBackgroundResource(R.drawable.im_spot_edit_edittext_bg);
        eTthuzhu.setPadding(padding15,padding15,padding15,padding15);
        Util.showSoftInput(eTthuzhu);
    }
    private void loseFocus(){
        eTthuzhu.setMinLines(1);
        eTthuzhu.setBackgroundResource(R.drawable.translate);
        eTthuzhu.setPadding(padding15,0,padding15,0);
        Util.hideSoftInputForce(eTthuzhu);
    }
}